package com.zigong.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.zigong.app.R;
import com.zigong.app.ui.adapter.holder.BaseAbsHolder;
import com.zigong.app.ui.adapter.holder.SearchResultTopicHolder;
import com.zigong.app.ui.adapter.holder.TopicDetailCommentHolder;
import com.zigong.app.ui.adapter.holder.TopicDetailSubHolder;
import com.zigong.app.ui.adapter.holder.TopicDetailTitleHolder;
import com.zigong.app.ui.adapter.holder.TopicDetailTopHolder;
import com.zigong.app.ui.adapter.holder.TopicDetailVideoHolder;
import com.zigong.app.ui.util.IListShowData;

import java.util.List;

/**
 * Created by Administrator on 2017/7/24 0024.
 */

public class TopicDeatilAdapter extends BaseHolderAbsAdapter<IListShowData, BaseAbsHolder<IListShowData>> {
    public static final int VIEWTYPE_TOP = 0;//专题栏目头部
    public static final int VIEWTYPE_VIDEO = 1;//专题栏目视频
    public static final int VIEWTYPE_TITLE = 2;//专题栏目title
    public static final int VIEWTYPE_COMMENT = 3;//专题栏目评论列表
    public static final int VIEWTYPE_SUB_TOPIC = 4;//专题栏目评论列表

    public TopicDeatilAdapter(Context context, List<IListShowData> list) {
        super(context, list);
    }

    @Override
    public BaseAbsHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseAbsHolder holder = null;
        LayoutInflater inflater = LayoutInflater.from(context);
        switch (viewType) {
            case VIEWTYPE_TOP:
                holder = new TopicDetailTopHolder(context, inflater.inflate(R.layout.item_topic_detail_top, parent, false));
                break;
            case VIEWTYPE_VIDEO:
                holder = new TopicDetailVideoHolder(context, inflater.inflate(R.layout.item_search_result_article_content, parent, false));
                break;
            case VIEWTYPE_TITLE:
                holder = new TopicDetailTitleHolder(context, inflater.inflate(R.layout.item_topic_detail_title, parent, false));
                break;
            case VIEWTYPE_COMMENT:
                holder = new TopicDetailCommentHolder(context, data,inflater.inflate(R.layout.item_topic_detail_comment, parent, false));
                holder.setInternalClick(this);
                break;
            case VIEWTYPE_SUB_TOPIC:
                holder = new TopicDetailSubHolder(context, inflater.inflate(R.layout.item_topic_detail_sub, parent, false));
                break;
        }
        return holder;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getDataViewType();
    }

    @Override
    public void onBindViewHolder(BaseAbsHolder<IListShowData> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setItemMode(position == getItemCount() - 1 ? BaseAbsHolder.ITEMMODE_LAST : BaseAbsHolder.ITEMMODE_NORMAL);
    }

    @Override
    public TopicDeatilAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        super.setItemInternalClick(itemInternalClick);
        return this;
    }

//    @Override
//    public int addData(FTopic fTopic) {
//        if (fTopic != null) {
//            if (data == null) {
//                data = new ArrayList<>();
//            }
//            int insert = data.size();
//            data.add(fTopic);
//            notifyItemInserted(insert);
//            notifyDataSetChanged();
//            return insert;
//        }
//        return -1;
//    }
}
